package com.gxa.modules.app.service.impl;

import com.gxa.modules.app.dto.MyCouponDto;
import com.gxa.modules.app.dto.MyCouponQueryDto;
import com.gxa.modules.app.mapper.CouponStoreMapper;
import com.gxa.modules.app.service.CouponStoreService;
import com.gxa.modules.sys.entity.Coupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CouponStoreServiceImpl implements CouponStoreService {

    @Autowired
    private CouponStoreMapper couponStoreMapper;

    @Override
    public List<Coupon> queryAllCoupon() {
        List<Coupon> couponList = this.couponStoreMapper.queryAllCoupon();
        for(int i=0;i<couponList.size();i++){
            java.sql.Date sqlDate = new java.sql.Date(couponList.get(i).getExpireTime().getTime());
            java.sql.Date sqlDate01 = new java.sql.Date(couponList.get(i).getCreateTime().getTime());
            couponList.get(i).setExpireTime(sqlDate);
            couponList.get(i).setCreateTime(sqlDate01);

        }
        return couponList;
    }

    @Override
    public List<MyCouponQueryDto> queryMyCouponById(MyCouponDto myCouponDto) {
        List<MyCouponQueryDto> myCouponList = this.couponStoreMapper.queryMyCouponById(myCouponDto);
        for(int i=0;i<myCouponList.size();i++){
            java.sql.Date sqlDate = new java.sql.Date(myCouponList.get(i).getExpireTime().getTime());
            java.sql.Date sqlDate01 = new java.sql.Date(myCouponList.get(i).getCreateTime().getTime());
            myCouponList.get(i).setExpireTime(sqlDate);
            myCouponList.get(i).setCreateTime(sqlDate01);
        }
        return myCouponList;
    }
}
